import getIn from './getIn';
import { URL_MODE_BLANK, URL_MODE_REPLACE } from './urlMode';

export default function webRouteHelper(params = {}) {
    const push = getIn(global, ['window', 'router', 'push']),
        pop = getIn(global, ['window', 'router', 'go']),
        replace = getIn(global, ['window', 'router', 'replace']),
        open = (pathname, query, queryString, urlMode) => getIn(global, ['window', 'open'])(queryString ? `${pathname}?${queryString}` : pathname, urlMode);
    const { pathname, urlMode, query, queryString, state } = params;
    // router 使用变量传递,未使用全局,在 Text等多个组件传递 this.props
    // 根据打开方式来判断
    if (urlMode === URL_MODE_BLANK && __PLATFORM__ && __PLATFORM__ === 'pc') {
        push(pathname, query, queryString, urlMode);
    } else if (urlMode === URL_MODE_REPLACE) {
        replace({ pathname, query, state });
    } else {
        push({ pathname, query, state });
    }
}
